package com.hn.controller;

import com.hn.mapper.LoginMapper;
import com.hn.pojo.Emp;
import com.hn.pojo.Result;
import com.hn.pojo.User;
import com.hn.utils.JwtUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.hn.utils.JwtUtils;
import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class LoginController {
    @Autowired
    private LoginMapper loginMapper;
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        User u=loginMapper.login(user);
        if(u!=null){
            Map<String,Object> map=new HashMap<String, Object>();
            map.put("username",u.getUsername());
            map.put("password",u.getPassword());
            String jwl=JwtUtils.getJwt(map);
            log.info("颁发jwt:"+jwl);
            return Result.success(jwl);
        }
        return Result.error("用户名或密码错误");
    }
}
